#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/11/7 18:09
# @Author  : 作者名
# @Site    :
from config import settings, mysql_param,redis_param
from router import handlers
from tornado import web
from tornado.web import StaticFileHandler
import peewee_async
import asyncredis

db = peewee_async.MySQLDatabase(**mysql_param)
db_obj = peewee_async.Manager(db)


class Application(web.Application):
    def __init__(self, *args, **kwargs):
        super(Application, self).__init__(*args, **kwargs)
        self.db = db
        self.db_obj = db_obj

        self.redis = asyncredis.connect(f"redis://{redis_param['host']}:{redis_param['port']}")


class StaticFileHandlerNew(StaticFileHandler):
    def __init__(self, *args, **kwargs):
        super(StaticFileHandlerNew, self).__init__(*args, **kwargs)
        self.xsrf_token
        self.set_secure_cookie("itcast", "ioioioioiooioio")


def creat_app():
    app = Application(handlers, **settings)  # 创建APP对象,设置路由
    return app
